﻿using System.ServiceModel.Channels;
using DevWeb.Biztalk.DeploymentSettings.DeploymentService.ClientProxy.ChannelPattern;
using DevWeb.Biztalk.DeploymentSettings.DeploymentService.Contracts;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.ServiceModel;

namespace DevWeb.Biztalk.DeploymentSettings.DeploymentService.Tests
{
    
    
    /// <summary>
    ///This is a test class for ProxyClientTest and is intended
    ///to contain all ProxyClientTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ProxyClientTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for ProxyClient`1 Constructor
        ///</summary>
        public void ProxyClientConstructorTestHelper<T>()
        {
            var target = SetupProxyClient();

            Assert.IsNotNull(target.Client);
            
            Assert.IsTrue(target.ClientChannelBase.State == CommunicationState.Opened);
            target.ClientChannelBase.Close();

        }

        

        [TestMethod()]
        public void GetSettings()
        {

            var target = SetupProxyClient();
             var productUpgradeCode = Guid.Parse("8E55E48E-2C3B-4A37-8750-4192B9EA38D9");
            var productId = Guid.Parse("F6EE55DA-16D2-4A90-AE0D-D684F45ACE5E");
            var settingslist = target.Client.GetEnvironmentSettings(productUpgradeCode, productId, "DEV");
        }


        [TestMethod()]
        public void GetSettings2()
        {

            var target = new ServiceReference1.DeploymentSettingsServiceClient();
            var productUpgradeCode = Guid.Parse("8E55E48E-2C3B-4A37-8750-4192B9EA38D9");
            var productId = Guid.Parse("F6EE55DA-16D2-4A90-AE0D-D684F45ACE5E");
            var settingslist = target.GetEnvironmentSettings(productUpgradeCode, productId, "DEV");

           Assert.IsNotNull(settingslist);
        }


        [TestMethod()]
        public void LogDeployment()
        {

            var target = new ServiceReference1.DeploymentSettingsServiceClient();
            var productUpgradeCode = Guid.Parse("8E55E48E-2C3B-4A37-8750-4192B9EA38D9");
            var productId = Guid.Parse("F6EE55DA-16D2-4A90-AE0D-D684F45ACE5E");
            string machine = Environment.MachineName;

            var deploy = target.LogDeployment(Environment.MachineName, Environment.UserName, "D", productId,
                productUpgradeCode, "DEV");



            Assert.IsTrue(deploy);
        }



        private static ProxyClient<IDeploymentSettingsService> SetupProxyClient()
        {
            EndpointAddress endpointaddress =
                new EndpointAddress("http://localhost/DeploymentService/DeploymentSettingService.svc/wshttp");

            Binding wshttpbinding = new WSHttpBinding(SecurityMode.None,false) ;

            

            ProxyClient<IDeploymentSettingsService> target = new ProxyClient<IDeploymentSettingsService>(endpointaddress,wshttpbinding);
            return target;
        }
    }
}
